package org.example;

import java.util.Scanner;

public class Test1 {
    //01背包
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt(), n = sc.nextInt();
        int[] weight = new int[m], value = new int[m];
        for (int i = 0; i < m; i++) {
            weight[i] = sc.nextInt();
        }
        for (int i = 0; i < m; i++) {
            value[i] = sc.nextInt();
        }

        // 使用一维数组优化空间复杂度
        int[] dp = new int[n+1];
        for (int i = 0; i < m; i++) {
            for (int j = n; j >= weight[i]; j--) { // 注意这里从n递减到weight[i]
                dp[j] = Math.max(dp[j], dp[j - weight[i]] + value[i]);
            }
        }
        System.out.println(dp[n]); // 输出最大价值
    }
}
